<?php
/**
 * Created by PhpStorm.
 * User: fengyan
 * Date: 17-7-6
 * Time: 下午2:43
 */

namespace App\Repositories\Admin;


use App\Models\Admin\Role;
use App\Models;
class RoleRepository extends AdminRepository
{
    public function __construct()
    {
        parent::__construct();
        $this->model = new Models\Admin\Role();
    }

    private static $instance;

    /**
     * 实现单例
     */
    public static function getInstance()
    {
        if (!(self::$instance instanceof self)) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    /**
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public function getList()
    {
        return $this->getSelectModel()->where('name', '<>', 'developer')->orderBy('id','asc')->get();
    }

    /**
     * 各个服务需实现自己的分页方法
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function getPaginateData(): \Illuminate\Contracts\Pagination\LengthAwarePaginator
    {
        return $this->getSelectModel()->orderBy('id','asc')->paginate($this->pageSize);
    }

    /**
     * 获取实例查询模型
     * @param array $filter
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function getSelectModel(array $filter = []) : \Illuminate\Database\Eloquent\Builder
    {
        $model = $this->model;

        $model = $model->where('id', '>', 0);

        return $model;
    }
}